home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / HyperXExamples / AExamples / Reduce.a < prev   
Encoding:
Text File  |  1998-12-03  |  1.8 KB  |  90 lines  |  [TEXT/MPS ]

  1. *
  2. *    Reduce    - XFCN to compress runs of spaces and tabs to a space
  3. *            - Fully MPW 3.0 compatible
  4. *
  5. *    Copyright © 1988 Apple Computer, Inc.
  6. *    All rights reserved.
  7. *
  8. *    Sample HyperTalk line:
  9. *
  10. *    put reduce(field 1) into field 1 -- reduce tabs & spaces
  11. *
  12. *
  13.  
  14.     CASE    OBJ
  15.     INCLUDE    'Traps.a'
  16.     INCLUDE    'HyperXCmd.a'
  17.  
  18.  
  19. LOCALS        EQU        0            ; Local storage will be on A6 stack frame, which
  20. h            EQU        LOCALS-4    ; always counts backwards, so values negative.
  21. LOCALSIZE    EQU        h
  22.  
  23.  
  24. ;            PROCEDURE EntryPoint(paramPtr: XCmdPtr);
  25. ENTRYPOINT    MAIN    EXPORT        ; build script uses ENTRYPOINT as main segment name.
  26.  
  27.         WITH    XCmdBlock
  28.     
  29.         ; Set up the stack frame for local variables.
  30.         
  31.         LINK    A6,#LOCALSIZE
  32.         MOVEM.L    A3/A4,-(SP)
  33.         
  34.         ; Get pointer to XCmdBlock
  35.         
  36.         MOVE.L    8(A6),A4            ; get paramPtr
  37.         CLR.L    returnValue(A4)        ; initialize return to empty
  38.         MOVE.W    paramCount(A4),D0
  39.         CMP.W    #1,D0                ; only XFCN parameter is input string
  40.         BNE.S    Done
  41.     
  42.     
  43.         ; The heart and soul of the XFCN goes here.
  44.  
  45. tab        EQU        9
  46. space    EQU        32
  47.  
  48.         MOVE.L    params(A4),A0        ; A0 = paramPtr->params[0]
  49.         _MoveHHi
  50.         MOVE.L    params(A4),A0
  51.         _GetHandleSize                ; How big is the original string?
  52.         _NewHandle                    ; Make room for a copy.
  53.         TST.W    D0                    ; Check error code
  54.         BNE.S    Done                ; Quit if no room
  55.         MOVE.L    A0,A3                ; Save handle for return
  56.     
  57.         MOVE.L    params(A4),A0
  58.         MOVE.L    (A0),A0                ; Get pointers to parse strings.
  59.         MOVE.L    (A3),A1
  60. Loop
  61.         MOVE.B    (A0)+,D0
  62.         CMP.B    #space,D0
  63.         BEQ.S    InnerLoop
  64.         CMP.B    #tab,D0
  65.         BNE.S    GotChar
  66. InnerLoop
  67.         MOVE.B    (A0)+,D0
  68.         CMP.B    #space,D0
  69.         BEQ.S    InnerLoop
  70.         CMP.B    #tab,D0
  71.         BEQ.S    InnerLoop
  72.         MOVE.B    #space,(A1)+
  73. GotChar
  74.         MOVE.B    D0,(A1)+
  75.         BNE.S    Loop
  76.     
  77.         MOVE.L    A3,returnValue(A4)
  78.  
  79. Done                                ; Return to HyperCard.
  80.         MOVEM.L    (SP)+,A3/A4
  81.         UNLK    A6
  82.         MOVE.L    (SP)+,A0            ; return address
  83.         ADDQ.L    #4,SP                ; clean off input parameter
  84.         JMP        (A0)
  85.     
  86.         ENDWITH
  87.         ENDMAIN
  88.     
  89.         END
  90.